package aeolus.wind.spider.web.commons.ability;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import aeolus.wind.spider.biz.dataobject.Ability;
import aeolus.wind.spider.biz.dataobject.AbilityPackage;
import aeolus.wind.spider.biz.service.interfaces.AbilityService;

/**
 * 相当于能力视图的概念，可以包裹任意多的能力
 * 
 * @author aeoluswind
 */
public class AbilityPackageItem {

    private AbilityPackage       abilityPackage;
    /**
     * 能力名和能力的map，一个package中的能力名字可以标示这个能力
     */
    private Map<String, Ability> abilityMap;

    public AbilityPackageItem(AbilityService abService, AbilityPackage abilityPackage) {
        this.abilityPackage = abilityPackage;
        this.abilityMap = new HashMap<String, Ability>();
        Set<String> abIdList = abilityPackage.getAbilityIdSet();
        for (String id : abIdList) {
            Ability ab = abService.findAbility(id);
            if (ab != null) abilityMap.put(ab.getName(), ab);
        }
    }

    public String getId() {
        return abilityPackage.getId();
    }

    public String getPackageName() {
        return abilityPackage.getPackageName();
    }

    public String getOwnIdentityName() {
        return abilityPackage.getOwnIdentityName();
    }

    public Collection<Ability> getAbilityCollection() {
        return abilityMap.values();
    }

    public Set<String> getAbilityNameSet() {
        return abilityMap.keySet();
    }
}
